package com.example.logistics_oa.controller;

import com.example.comment_oa.pojos.BelateMoney;
import com.example.comment_oa.pojos.FiveGold;
import com.example.comment_oa.pojos.JobMakeoffer;
import com.example.comment_oa.pojos.JobcorresSubsidy;
import com.example.comment_oa.pojos_vo.salaryVo.EmpSalary;
import com.example.comment_oa.pojos_vo.salaryVo.EmpSalarySelect;
import com.example.comment_oa.response.AjaxResponse;
import com.example.logistics_oa.mapper.JobcorresSubsidyMapper;
import com.example.logistics_oa.service.BelateMoneyService;
import com.example.logistics_oa.service.FiveGoldService;
import com.example.logistics_oa.service.JobMakeofferService;
import com.example.logistics_oa.service.JobcorresSubsidyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/logisticsOa")
@CrossOrigin
public class ChaXunXiangqingController {

    //岗位津贴的service
    @Autowired
    JobMakeofferService jobMakeofferService;
    //职位补贴
    @Autowired
    JobcorresSubsidyService jobcorresSubsidyService;
    //全勤奖
    @Autowired
    BelateMoneyService belateMoneyService;
    //五险一金
    @Autowired
    FiveGoldService fiveGoldService;

    @PostMapping("/selectSalary")
    public AjaxResponse chaxunxiangqing(@RequestBody EmpSalarySelect empSalarySelect){
        //岗位津贴在这里
        List<JobMakeoffer> jobMakeoffers = jobMakeofferService.selectGangWeiJinTie(empSalarySelect.getDepartmentId(), empSalarySelect.getJobId());
        //职位对应补助在这里
        List<JobcorresSubsidy> jobcorresSubsidies = jobcorresSubsidyService.selectBuTieXiangQingAnd(empSalarySelect.getJobId(), empSalarySelect.getDepartmentId());
        //全勤奖
        List<BelateMoney> belateMonies = belateMoneyService.selectById();
        //五险一金
        List<FiveGold> fiveGolds = fiveGoldService.selectAll();

        EmpSalary empSalary = new EmpSalary();
        //实习期是基本薪资的80%，并且没有五险一金
        if(empSalarySelect.getEmpStatus()==0){
            //基本薪资
            empSalary.setJibenxinzi(empSalarySelect.getJibenSalary()*0.8);
            //岗位津贴
            empSalary.setGangweijintie(0.0);

            //职位补贴

            empSalary.setZhiwubutie(0.0);
            //全勤奖
            empSalary.setQuanqinjiang(0.0);

            // 五险一金



            empSalary.setWuxianyijinkoukuan(0.0);

            empSalary.setZonghe(empSalary.getJibenxinzi()+empSalary.getGangweijintie()+empSalary.getZhiwubutie()+empSalary.getQuanqinjiang()-empSalary.getWuxianyijinkoukuan());


        }else if(empSalarySelect.getEmpStatus()==1){
            //基本薪资
            empSalary.setJibenxinzi(empSalarySelect.getJibenSalary());
            //岗位津贴
            empSalary.setGangweijintie(jobMakeoffers.get(0).getJmoJobsalary());

            //职位补贴
            Double zhiwubutie =0.0;
            for (JobcorresSubsidy j : jobcorresSubsidies) {
                zhiwubutie+= j.getJcsMoney();
            }
            empSalary.setZhiwubutie(zhiwubutie);
            //全勤奖
            empSalary.setQuanqinjiang(belateMonies.get(0).getBlMoney());

            // 五险一金
            Double wuxianBili =0.0;
            for (FiveGold fiveGold : fiveGolds) {
                wuxianBili += fiveGold.getFxCmopare();
            }
            Double  wuxianyijinkoukuan= empSalarySelect.getJibenSalary() * wuxianBili;

            empSalary.setWuxianyijinkoukuan(wuxianyijinkoukuan);

            empSalary.setZonghe(empSalary.getJibenxinzi()+empSalary.getGangweijintie()+empSalary.getZhiwubutie()+empSalary.getQuanqinjiang()-empSalary.getWuxianyijinkoukuan());

        }


//        System.err.println(empSalarySelect);
        System.err.println(empSalary);
        List<EmpSalary> ee = new ArrayList<>();
        ee.add(empSalary);
        return  AjaxResponse.success(ee);
    }

}
